package com.xprime.mobileFramework.file;

import java.io.File;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREInvalidObjectException;
import com.adobe.fre.FREObject;
import com.adobe.fre.FRETypeMismatchException;
import com.adobe.fre.FREWrongThreadException;

public class FileExist implements FREFunction {
	
	@Override
	public FREObject call( FREContext pFREContext, FREObject[] arg1) {
		
		FREObject result = null;
		
		String path = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
		
		
		File file;
		try
		{
			String fullFilePath = path + "/" + arg1[0].getAsString();
			file = new File( fullFilePath );
			
			if( file.exists() )
			{
				result = FREObject.newObject(true);
			}
			else
			{
				result = FREObject.newObject(false);
			}
		}
		catch (FREWrongThreadException e)
		{
			e.printStackTrace();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FRETypeMismatchException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FREInvalidObjectException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return result;
	}

}
